<template>
  <div>
    <div class="container">
      <div class="handle-box">
        <el-select v-model="query.case_source" @change="handleSearch(query.case_number,query.tcs_note_id,query.case_source,query.case_type)" clearable placeholder="案件来源" class="handle-select mr10">
          <el-option key="1" label="市场查获" value="市场查获"></el-option>
          <el-option key="2" label="投诉举报" value="投诉举报"></el-option>
          <el-option key="3" label="上级交办" value="上级交办"></el-option>
        </el-select>
        <el-select v-model="query.case_type" @change="handleSearch(query.case_number,query.tcs_note_id,query.case_source,query.case_type)" clearable placeholder="案件性质" class="handle-select mr10">
          <el-option key="1" label="一般案件" value="一般案件"></el-option>
          <el-option key="2" label="简易案件" value="简易案件"></el-option>
        </el-select>
        <el-input v-model="query.case_number" placeholder="立案编号" @change="handleSearch(query.case_number,query.tcs_note_id,query.case_source,query.case_type)" class="handle-input mr10"></el-input>
        <el-button type="primary" :icon="Search" @change="handleSearch(query.case_number,query.tcs_note_id,query.case_source,query.case_type)">搜索</el-button>
      </div>
      <el-table :data="tableList" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <!--        <el-table-column prop="case_id" label="案件号" width="100" align="center"></el-table-column>-->
        <el-table-column prop="case_source" label="案件来源" align="center"></el-table-column>
        <el-table-column prop="case_number" label="立案编号" width="200" align="center"></el-table-column>
        <el-table-column prop="case_update_time" label="更新时间"  align="center"></el-table-column>
        <el-table-column prop="case_type" label="案件性质" align="center"></el-table-column>
        <el-table-column prop="date_of_filing" label="立案日期"  align="center"></el-table-column>
        <el-table-column label="询问笔录状态" align="center" width="180">
          <template #default="scope">
            <div v-if="scope.row.tcs_note_id === '涉案烟草价品核案表完成' ">
              <el-tag :type=" 'danger'">涉案烟草价品核案表完成 </el-tag>
            </div>

            <div v-if="scope.row.tcs_note_id === '询问笔录已完成' ||
            scope.row.tcs_note_id === '已完成' ||
            scope.row.tcs_note_id === '无证经营公示已完成' ||
            scope.row.tcs_note_id ==='调查终结文书已完成'||
            scope.row.tcs_note_id ==='案件处理审批已开始'||
            scope.row.tcs_note_id ==='集体讨论已开始'||
            scope.row.tcs_note_id ==='集体讨论已完成'||
            scope.row.tcs_note_id ==='听证已开始'||
            scope.row.tcs_note_id ==='听证告知书已完成'||
            scope.row.tcs_note_id ==='听证已完成'||
            scope.row.tcs_note_id ==='案件处理审批已完成'||
            scope.row.tcs_note_id ==='行政处罚事先告知书确认完成'||
            scope.row.tcs_note_id ==='行政处罚事先告知书已完成'||
            scope.row.tcs_note_id ==='行政处罚决定书确认完成'||
            scope.row.tcs_note_id ==='行政处罚决定书已完成'||
            scope.row.tcs_note_id ==='行政罚款收据上传完成'||
            scope.row.tcs_note_id ==='行政罚款收据已完成'||
            scope.row.tcs_note_id ==='结案报告表已完成'||
            scope.row.tcs_note_id ==='撤案集体讨论准备'||
            scope.row.tcs_note_id ==='撤案集体讨论已开始'">
              <el-tag :type=" 'success'">已完成 </el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="下一步操作" width="300" align="center">
          <template #default="scope">
            <div v-if="scope.row.tcs_note_id === '涉案烟草价品核案表完成' ">
              <el-button text :icon="Edit" class="blue" @click="inquiry_record_tabel(scope.row)" >
                询问笔录查看及确认
              </el-button>
            </div>

            <div v-if="scope.row.tcs_note_id === '询问笔录已完成' ||
            scope.row.tcs_note_id === '已完成' ||
            scope.row.tcs_note_id === '无证经营公示已完成' ||
            scope.row.tcs_note_id ==='调查终结文书已完成'||
            scope.row.tcs_note_id ==='案件处理审批已开始'||
            scope.row.tcs_note_id ==='集体讨论已开始'||
            scope.row.tcs_note_id ==='集体讨论已完成'||
            scope.row.tcs_note_id ==='听证已开始'||
            scope.row.tcs_note_id ==='听证告知书已完成'||
            scope.row.tcs_note_id ==='听证已完成'||
            scope.row.tcs_note_id ==='案件处理审批已完成'||
            scope.row.tcs_note_id ==='行政处罚事先告知书确认完成'||
            scope.row.tcs_note_id ==='行政处罚事先告知书已完成'||
            scope.row.tcs_note_id ==='行政处罚决定书确认完成'||
            scope.row.tcs_note_id ==='行政处罚决定书已完成'||
            scope.row.tcs_note_id ==='行政罚款收据上传完成'||
            scope.row.tcs_note_id ==='行政罚款收据已完成'||
            scope.row.tcs_note_id ==='结案报告表已完成'||
            scope.row.tcs_note_id ==='撤案集体讨论准备'||
            scope.row.tcs_note_id ==='撤案集体讨论已开始'">
              <el-button text :icon="Edit" class="blue" @click="inquiry_record_browse(scope.row)" >
                查看询问笔录
              </el-button>
            </div>

          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
            background
            layout="total, prev, pager, next"
            :current-page="query.pageIndex"
            :page-size="query.pageSize"
            :total="pageTotal"
            @current-change="handlePageChange"
        ></el-pagination>
      </div>
    </div>
    <el-dialog title="询问笔录填写" v-model="Transcript_of_questioning_Visible" width="80%">
      <el-form ref="form"  :model="form" label-width="100px">
        <el-row>
          <el-col :span="7">
            <el-form-item label="询问时间">
              <el-date-picker v-model="inquiry_record_data_storage.date_of_filing"  type="datetime" placeholder="选择询问日期" value-format="YYYY-MM-DD HH:mm:ss">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="save_inquired_person"> <el-button type="primary"   @click="save_inquired_person">保存被询问人信息</el-button></div>
          </el-col>
        </el-row>
        <el-form-item label="询问地点">
          <el-input v-model="inquiry_record_data_storage.tce_address"></el-input>
        </el-form-item>
        <el-row>
          <el-col :span="6">
            <el-form-item label="被询问人">
              <el-input v-model="inquiry_record_data_storage.mer_person"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="性别">
              <el-select v-model="inquiry_record_data_storage.gender"  placeholder="请选择" class="handle-select mr10">
                <el-option key="1" label="男" value="男" ></el-option>
                <el-option key="2" label="女" value="女"></el-option>
              </el-select>
            </el-form-item>
          </el-col >

          <el-col :span="6">
            <el-form-item label="年龄" >
              <!--              <el-select  placeholder="请选择"  class="handle-select mr10"></el-select>-->
              <el-input v-model="inquiry_record_data_storage.tir_age"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="民族">
              <el-input v-model="inquiry_record_data_storage.nation"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="6">
            <el-form-item label="籍贯">
              <el-input v-model="inquiry_record_data_storage.native_place"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="身份证号码" >
              <!--              <el-select  placeholder="请选择"  class="handle-select mr10"></el-select>-->
              <el-input v-model="inquiry_record_data_storage.identity_card"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住址">
              <el-input v-model="inquiry_record_data_storage.family_address"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--          <el-col :span="8">-->
          <!--            -->
          <!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="经营地址">
              <el-input v-model="inquiry_record_data_storage.business_address"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话">
              <el-input v-model="inquiry_record_data_storage.telephone_number"></el-input>
            </el-form-item>
          </el-col>

        </el-row>


        <el-row :gutter="24">

          <el-col :span="8">
            <el-form-item label="询问人">
              <el-select v-model="inquiry_record_data_storage.user_name_1" @change="get_interrogator_clause_opinion(create_case.interrogator)" clearable filterable placeholder="请选择">
                <el-option
                        v-for="(item,index) in interrogator_Data"
                        :key='index'
                        :label='item.staff_name'
                        :value='item.staff_id'
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="询问人" >
              <el-select v-model="inquiry_record_data_storage.user_name_2" @change="get_interrogator_clause_opinion(create_case.interrogator)" clearable filterable placeholder="请选择">
                <el-option
                        v-for="(item,index) in interrogator_Data"
                        :key='index'
                        :label='item.staff_name'
                        :value='item.staff_id'
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="记录人">
              <el-select v-model="inquiry_record_data_storage.recorder" @change="get_recorder_clause_opinion(create_case.recorder)" clearable filterable placeholder="请选择">
                <el-option
                        v-for="(item,index) in recorder_Data"
                        :key='index'
                        :label='item.staff_name'
                        :value='item.staff_name'
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="确认记录">
          <el-input v-model="inquiry_record_data_storage.confirm_record" type="textarea" rows="2" :disabled="true" ></el-input>
        </el-form-item>
        <el-form-item label="告知权利">
          <el-input type="textarea" rows="3" :disabled="true"  model-value="根据《烟草专卖行政处罚程序规定》第二十条、第二十六条第一款的规定，你应当如实回答询问，不得提供伪证或隐匿证据，否则将承担相应的法律责任，同时你依法享有陈述权、申辩权和申请办案人员回避的权利。请问你是否清楚？是否申请回避？"></el-input>
        </el-form-item>
        <el-form-item label="被询问人">
          <el-input type="textarea" rows="1" :disabled="true"  model-value="我听清楚了，愿意接受你们的询问"></el-input>
        </el-form-item>
        <el-row>


        </el-row>
        <el-row :gutter="24">
          <el-col :span="500">
            <el-form-item label="模糊查询问题" >
              <el-select v-model="question_answer_storage.question_selection" @change="get_question_clause_opinion(question_answer_storage.question_selection)" clearable filterable placeholder="请选择">
                <el-option
                        v-for="item in question_Data"
                        :key="item.id"
                        :label="item.question"
                        :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>

          </el-col >
          <div  align="right" class="default_answer">
            <el-button type="primary"   @click="default_answer_show">默认回答</el-button>
          </div>&nbsp;&nbsp;
          <div  align="right" class="question_answer">
            <el-button type="primary" color="#00a854"  @click="question_answer_add">继续录入问答</el-button>
          </div>
        </el-row>
        <el-form-item label="问">
          <el-input type="textarea" rows="2" class="el-input" v-model="question_answer_storage.question"  placeholder="请输入或修改问题"></el-input>

        </el-form-item>
        <el-form-item label="答">
          <el-input type="textarea" rows="3"  v-model="question_answer_storage.answer" ></el-input>

        </el-form-item>

      </el-form>

      <el-table :data="question_answer_Data" border class="table" ref="multipleTable" header-cell-class-name="table-header" >
        <!--            <el-table-column prop="id" label="序号"  width="55px" align="center"></el-table-column>-->
        <el-table-column prop="question" label="问"   align="center"></el-table-column>
        <el-table-column prop="answer" label="答"   align="center"></el-table-column>

        <el-table-column label="操作" width="283px"  align="center">
          <template #default="scope">
            <!--          <el-button text :icon="Edit" @click="move_question_answer(scope.$index, scope.row)" v-permiss="1">-->
            <!--            上移-->
            <!--          </el-button>-->
            <el-button text :icon="Edit" @click="inquiryEdit(scope.$index, scope.row)" >
              修改
            </el-button>
            <el-button text :icon="Delete" class="red" @click="question_answer_delete(scope.$index,scope.row)" >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
              <span class="dialog-footer">
                <el-button @click="Transcript_of_questioning_Visible = false">取 消</el-button>
        <el-button color="#00a854" type="primary" @click="certain_inquiry_record">确 定</el-button>
              </span>
      </template>
    </el-dialog>



    <el-dialog  v-model="Inquiry_record_list_Browse_Visible" width="50%">
      <html>
      <head>
        <title>询问笔录</title>
      </head>
      <body>
      <h1 align="center">
        福建省福州市闽侯县烟草专卖局
      </h1>
      <h2 align="center">
        询问笔录
      </h2>
      <br>
      <div >
        <font size="3">
          <b>询问时间：</b>{{inquiry_record_browse_data.date_of_filing}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font>
      </div>
      <div >
        <font size="3">
          <b>询问地点：</b>{{inquiry_record_browse_data.tce_address}}
        </font>
      </div>
      <div >
        <font size="3" >
          <b> 询问人：</b>{{inquiry_record_browse_data.user_name_1}}&nbsp;&nbsp;{{inquiry_record_browse_data.user_name_2}} &nbsp;&nbsp;  记录人：{{inquiry_record_browse_data.recorder}}
        </font>
      </div>
      <div >
        <font size="3">
          <b> 被询问人：</b>{{inquiry_record_browse_data.mer_person}}  &nbsp;&nbsp;性别：{{inquiry_record_browse_data.gender}}&nbsp;&nbsp;民族：{{inquiry_record_browse_data.nation}}
        </font>
      </div>
      <div >
        <font size="3">
          <b> 证件类型及号码：</b>{{inquiry_record_browse_data.identity_card}}(身份证)&nbsp;&nbsp;<b>住址：</b>{{inquiry_record_browse_data.family_address}}
        </font>
      </div>
      <div >
        <font size="3">
          <b>经营地址：</b>{{inquiry_record_browse_data.business_address}} &nbsp;&nbsp; <b>联系电话：</b>{{inquiry_record_browse_data.telephone_number}}
        </font>
      </div>
      <div >
        <font size="3">
          <b>执法人员表明身份、出示证件及被询问人确认的记录：</b>{{inquiry_record_browse_data.confirm_record}}
        </font>
      </div>
      <div >
        <font size="3">
          <b>告知陈述（申辩）和申请回避的权利：</b>{{inquiry_record_browse_data.inform_right}}
        </font>
      </div>
      <div >
        <font size="3">
          <b>被询问人：</b>{{inquiry_record_browse_data.tir_person_answer}}
        </font>
      </div>
      <div v-for="item in inquiry_record_browse_data.question_answer_list">
        <font size="3">
          <b>问：</b>{{item.question}}&nbsp;&nbsp;&nbsp;</font><br>
        <font size="3">
          <b>答：</b>{{item.answer}}&nbsp;&nbsp;&nbsp;
        </font>

      </div>

      <div >
        <font size="3">
          <b>问：</b>{{inquiry_record_browse_data.end_confirm}}
        </font>
      </div>
      <div >
        <font size="3">
          <b> 以上笔录经被询问人核对无误。</b>
        </font>
      </div>
      <div >
        <font size="3">
          被询问人（签名）：<b><u>______________________________________________</u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;日
        </font>
      </div>
      <div >
        <font size="3">
          询&nbsp;问&nbsp;&nbsp;&nbsp;人（签名）：<b><u>__________________</u></b>执法证号:<b><u>____________________{{}} </u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;日
        </font>
      </div>
      <div >
        <font size="3">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><u>__________________</u></b>执法证号:<b><u>____________________{{}} </u></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;日
        </font>
      </div>
      </body>

      </html>
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="Inquiry_record_list_Browse_Visible=false" >取 消</el-button>
                <el-button type="primary" :icon="Printer"  @click="inquiry_record_print" >
                打 印
              </el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 问题回答修改弹出框 -->
    <el-dialog title="修改" v-model="InquiryEditVisible" width="50%">
      <el-form label-width="80px">
        <el-form-item label="案件号">
          <el-input v-model="question_answer_data_edit.case_id" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="问题号">
          <el-input v-model="question_answer_data_edit.id" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="问题">
          <el-input type="textarea" rows="3" v-model="question_answer_data_edit.question" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="回答">
          <el-input type="textarea" rows="3" v-model="question_answer_data_edit.answer" ></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
              <span class="dialog-footer">
                  <el-button @click="InquiryEditVisible = false">取 消</el-button>
                  <el-button type="primary" @click="saveInquiryEdit">确 定</el-button>
              </span>
      </template>
    </el-dialog>




  </div>
</template>

<script setup lang="ts" name="basetable">
import { ref, reactive } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { Delete, Edit, Search, Plus,Printer } from '@element-plus/icons-vue';
import {
  case_evi_Create,
  case_evi_Views,
  case_legal_Create,
  ciga_evudence_Create,
  end_record_data,
  evi_Views,
  fetchData_case,
  fetchData_case_Create,
  fetchData_case_update,
  fetchData_legal_clause,
  fetchData_mer,
  fetchData_s_mongodb_evidence_Cre,
  fetchData_s_mongodb_evidence_Views,
  fetchData_tobacco,
  fetchData_user,
  illegal_record_data,
  illegal_record_Search,
  mer_Create,
  mer_search_api,
  review_price_data,
  staff_evidence_create,
  staff_evidence_data,
  end_record_show,
  record_inquiry_show,
  record_inquiry_print,
  case_evidence_Views,
  case_evidence_Edit,
  question_answer_clause_delete,
  price_review_clause_delete,
  fetchData_user_Edit,
  fetchData_price_Edit,
  question_answer_show,
  question_answer_Create,
  fetchData_interrogator_clause,
  fetchData_recorder_clause, fetchData_question_clause, inquiry_record_data, fetchData_question_answer_Edit, fetchData_inquiry_record_Confirm, inquiry_record_print_data, question_answer_move, default_answer
} from '../api/index';
import {
  export_word_1, export_word_6
} from './table_inquiry.vue'

//案件表数据
interface TableItem {
  case_id:number,
  date_of_filing:string,
  date_of_closing:string,
  date_of_archive:string,
  case_source:string,
  case_number:string,
  archive_person:string,
  case_update_time:string,
  ase_type:string,
  case_remark:string,
  tcs_note_id:string,
  ciga_flag:string,
  ciga_num_flag:string,
  mer_flag:string,
}

//案件暂存数据
const create_case = reactive({
  case_id:0,
  staff_evi_id:0,
  staff_id:0,
  staff_evi_send_per:'',
  staff_evi_check_per1:'',
  staff_evi_check_per2:'',
  staff_evi_send_time:'',
  staff_evi_send_unit:'',
  staff_evi_send_result:'',
  staff_evi_rec_address:'',
  staff_evi_status:'',
  staff_evi_per_note:'',
  mer_flag:'',
  ciga_num_flag:'',
  ciga_flag:'',
  test:[],
  img_data:'',
  standard:'',
  tir_id:0,
  tlc_id:0,
  illegal_behavior:'',
  evi_id_number:'',
  evi_id:'',
  date_of_filing:'',
  date_of_closing:'',
  date_of_archive:'',
  case_source:'',
  case_number:'',
  archive_person:'',
  case_update_time:'',
  case_type:'',
  case_remark:'',
  mer_id:0,
  tcs_note:'',
  tce_time:'',
  tce_number:0,
  tce_amount:0,
  tce_remark:'',
  tce_address:'福建省福州市闽侯县烟草专卖局',
  evi_number:0,//数量(条)
  ciga_variety:'',//品种
  barcode:'',//条形码
  ciga_model:'',//规格型号
  ciga_price:0,//单价
  inkjet:'',//
  mer_format:'',
  mer_address:'',
  mer_person:'',
  mer_record:'',
  date_of_record:'',
  date_of_effect:'',
  date_of_issue:'',
  mer_hometown:'',
  mer_id_number:'',
  mer_tel:'',
  business_licence_code:'',
  licence_state:'',
  storage_address:'',
  retail_licence_code:'',
  category:'',
  area_id:0,
  mer_zip_code:0,
  mer_name:'',
  remark:'',
  question:'',
  answer:'',
  interrogator:'',
  id:0,
});
//获取商户数据用作选项框
interface mer_data {
  mer_id: number,
  mer_format: string,
  mer_address: string,
  mer_person: string,
  mer_record: string,
  date_of_record: string,
  date_of_effect: string,
  date_of_issue: string,
  mer_hometown: string,
  mer_id_number: string,
  mer_tel: string,
  business_licence_code: string,
  licence_state: string,
  storage_address: string,
  retail_licence_code: string,
  category: string,
  area_id: number,
  mer_zip_code: number,
  mer_name: string,
}
const mer_Data = ref<mer_data[]>([]);
const get_mer_opinion = (mer_name:string='',licence_state:string='',mer_person:string='' ,mer_id:number,business_licence_code:string='') =>{
  fetchData_mer(mer_name,licence_state,mer_person,mer_id,business_licence_code).then(res =>{
    mer_Data.value = res.data.data;
  })
}
get_mer_opinion();
//获取执法人员数据作为选择框
interface staff_data{
  staff_id:number,
  staff_name:string,
  staff_gender:string,
  staff_birthday:string,
  staff_ethnicity:string,
  staff_edu_bg:string,
  staff_email:string,
  field_staff_identity_card:string,
  staff_hometown:string,
  staff_degree:string,
  staff_political_status:string,
  staff_post:string,
  staff_account_no:string,
  staff_account_pwd:string,
  staff_starting_time:string,
  staff_authorized:string,
  staff_phone:string,
  staff_tel:string,
  staff_e_sign:string,
  staff_small_number:string,
  staff_license_no:string,
  staff_now_work_degree:string,
  staff_now_evaluate_degree:string,
}
const staff_Data = ref<staff_data[]>([]);
const get_staff_opinion1 = () =>{
  fetchData_user('','','').then(res=>{
    staff_Data.value = res.data.data;
  })
}
get_staff_opinion1();

//获取案由信息数据用作选项框
interface illegal_data {
  tlc_id:number,
  illegal_behavior:string,
  standard:string,
  penalty_range:string,
  statutory_penalty:string,
  grade:string,
  remark:string,
}
const illegal_Data = ref<illegal_data[]>([]);
const get_legal_clause_opinion = (illegal_behavior:string='',standard:string='' ,grade:string='',tlc_id:number) =>{
  fetchData_legal_clause(illegal_behavior, standard,grade,tlc_id).then(res =>{
    illegal_Data.value = res.data.data;
  })
}
get_legal_clause_opinion();


//视图/

const Ratification_Visible = ref(false);                              //批准书视图
const Ratification_Edit_Visible = ref(false);                         //批准书修改视图
const Advice_note_Visible = ref(false);                               //通知书视图
const Advice_note_Views_Visible = ref(false);                         //查看通知书视图
const Price_list_Visible = ref(false);                                //核价表视图
const Price_list_Browse_Visible = ref(false);                         //核价表视图
const Transcript_of_questioning_Visible=ref(false);                   //询问笔录视图
const Inquiry_record_list_Browse_Visible=ref(false);                 //查看询问笔录



//通过案件号查询所有证据先行保存通知书
interface Evidence_case_data {
  evi_id:number,
  case_id:number,//案件号
  evi_id_number:string,
  evi_number:number,
  tce_time_year:string,//案件时间
  tce_time_month:string,
  tce_time_day:string,
  tce_type_number:string,
  tce_number:string,
  tce_amount:number,
  tce_remark:string,
  tce_address:string,
  single_total:string,
}
const evidence_case_Data= ref<Evidence_case_data[]>([]);
//核价表信息显示
const get_review_price_Data=(case_id:number)=>{
  evi_Views("",case_id).then(res=>{
    evidence_ciga_Data.value = res.data.data;
  })
}

//暂存核价表信息
const price_review_data_storage=reactive({
  year:'',
  case_number:'',
  list1:[],
  case_source:'',
  month:'',
  day:'',
  hour:'',
  min:'',
  mer_address:'',
  mer_person:'',
  retail_licence_code:'',
  mer_id_number:'',
  mer_hometown:'',
  area_name:'',
  mer_name:'',
  list2:[],
  tce_type_number:'',
  tce_number:'',
  list3:[],
  tce_amount:'',
  evi_id_number:'',
})
//获取核价表信息
const get_price_review_data_storage=(row:any)=>{
  illegal_record_data(row.case_id).then(res=>{
    price_review_data_storage.year=res.data.data.year;
    price_review_data_storage.case_number=res.data.data.case_number;
    price_review_data_storage.list1=res.data.data.list1;
    price_review_data_storage.case_source=res.data.data.case_source;
    price_review_data_storage.month=res.data.data.month;
    price_review_data_storage.day=res.data.data.day;
    price_review_data_storage.hour=res.data.data.hour;
    price_review_data_storage.min=res.data.data.min;
    price_review_data_storage.mer_address=res.data.data.mer_address;
    price_review_data_storage.mer_person=res.data.data.mer_person;
    price_review_data_storage.retail_licence_code=res.data.data.retail_licence_code;
    price_review_data_storage.mer_id_number=res.data.data.mer_id_number;
    price_review_data_storage.mer_hometown=res.data.data.mer_hometown;
    price_review_data_storage.area_name=res.data.data.area_name;
    price_review_data_storage.mer_name=res.data.data.mer_name;
    price_review_data_storage.list2=res.data.data.list2;
    price_review_data_storage.tce_type_number=res.data.data.tce_type_number;
    price_review_data_storage.tce_number=res.data.data.tce_number;
    price_review_data_storage.list3=res.data.data.list3;
    price_review_data_storage.tce_amount=res.data.data.tce_amount;
    price_review_data_storage.evi_id_number=res.data.data.evi_id_number;
  })
}

//询问笔录暂存数据
const inquiry_record_data_storage=reactive({
  case_id:0,
  date_of_filing:'',//询问时间
  tce_address:'',//询问地点 1
  user_id_1:0,//询问人员1编号
  user_name_1:'',//询问人员1
  user_id_2:0,//询问人员2编号
  user_name_2:'',//询问人员2
  recorder:'',//记录员
  mer_person:'',//被询问人
  gender:'',//被询问人性别
  nation:'',//被询问人民族
  identity_card:'',//身份证号码
  family_address:'',//住址
  business_address:'',//经营地址
  telephone_number:'',//联系电话
  confirm_record:'',//确认记录
  native_place:'',//籍贯
  tir_age:'',//年龄
})

//获取询问笔录信息
const get_inquiry_record_data_storage=(row:any)=>{
  inquiry_record_data(row.case_id,row.evi_id_number).then(res=>{
    inquiry_record_data_storage.case_id=create_case.case_id;
    // inquiry_record_data_storage.date_of_filing=res.data.data.date_of_filing;
    inquiry_record_data_storage.tce_address=res.data.data.tce_address;
    inquiry_record_data_storage.user_id_1=res.data.data.user_id_1;
    inquiry_record_data_storage.user_name_1=res.data.data.user_name_1;
    inquiry_record_data_storage.user_id_2=res.data.data.user_id_2;
    inquiry_record_data_storage.user_name_2=res.data.data.user_name_2;
    inquiry_record_data_storage.recorder=res.data.data.recorder;
    inquiry_record_data_storage.mer_person=res.data.data.mer_person;
    inquiry_record_data_storage.gender=res.data.data.gender;
    inquiry_record_data_storage.nation=res.data.data.nation;
    inquiry_record_data_storage.identity_card=res.data.data.identity_card;
    inquiry_record_data_storage.family_address=res.data.data.family_address;
    inquiry_record_data_storage.business_address=res.data.data.business_address;
    inquiry_record_data_storage.telephone_number=res.data.data.telephone_number;
    inquiry_record_data_storage.confirm_record=res.data.data.confirm_record;
    inquiry_record_data_storage.tir_age=res.data.data.tir_age;
    inquiry_record_data_storage.native_place=res.data.data.native_place;
  })
}

//询问笔录浏览数据
const inquiry_record_browse_data=reactive({
  date_of_filing:'',//案发时间
  tce_address:'',//询问地点 1
  user_id_1:0,//询问人员1编号
  user_name_1:'',//询问人员1
  user_id_2:0,//询问人员2编号
  user_name_2:'',//询问人员2
  staff_license_1:'',
  staff_license_2:'',
  recorder:'',//记录员
  mer_person:'',//被询问人
  gender:'',//被询问人性别
  nation:'',//被询问人民族
  identity_card:'',//身份证号码
  family_address:'',//住址
  business_address:'',//经营地址
  telephone_number:'',//联系电话
  confirm_record:'',//确认记录
  inform_right:'',
  tir_person_answer:'',
  question_answer_list:[],
  end_confirm:'',
})



//获取询问笔录浏览信息
const get_inquiry_record_browse_data=()=>{

  inquiry_record_print_data(create_case.case_id).then(res=>{
    inquiry_record_browse_data.date_of_filing=res.data.data.inquiry_time;
    inquiry_record_browse_data.tce_address=res.data.data.tce_address;
    inquiry_record_browse_data.user_id_1=res.data.data.user_id_1,//询问人员1编号
    inquiry_record_browse_data.user_name_1=res.data.data.user_name_1,//询问人员1
    inquiry_record_browse_data.user_id_2=res.data.data.user_id_2,//询问人员2编号
    inquiry_record_browse_data.user_name_2=res.data.data.user_name_2,//询问人员2
    inquiry_record_browse_data.recorder=res.data.data.recorder,//记录员
    inquiry_record_browse_data.staff_license_1=res.data.data.staff_license_1;
    inquiry_record_browse_data.staff_license_2=res.data.data.staff_license_2;
    inquiry_record_browse_data.mer_person=res.data.data.tir_person;//被询问人
    inquiry_record_browse_data.gender=res.data.data.tir_gender;//被询问人性别
    inquiry_record_browse_data.nation=res.data.data.tir_nation;//被询问人民族
    inquiry_record_browse_data.identity_card=res.data.data.tir_id_number;//身份证号码
    inquiry_record_browse_data.family_address=res.data.data.tir_home;//住址
    inquiry_record_browse_data.business_address=res.data.data.address;//经营地址
    inquiry_record_browse_data.telephone_number=res.data.data.tel;//联系电话
    inquiry_record_browse_data.confirm_record=res.data.data.confirm_record;//确认记录
    inquiry_record_browse_data.inform_right=res.data.data.inform_right;
    inquiry_record_browse_data.tir_person_answer=res.data.data.tir_person_answer;
    inquiry_record_browse_data.question_answer_list=res.data.data.question_answer_list;
    inquiry_record_browse_data.end_confirm=res.data.data.end_confirm;
  })
}

//打印询问笔录
const inquiry_record_print=()=>{
  inquiry_record_print_data(create_case.case_id).then(res=>{
    export_word_6(
            res.data.data.inquiry_time,
            res.data.data.tce_address,
            res.data.data.user_id_1,
            res.data.data.user_id_2,
            res.data.data.user_name_1,
            res.data.data.user_name_2,
            res.data.data.recorder,
            res.data.data.staff_license_1,
            res.data.data.staff_license_2,
            res.data.data.tir_person,
            res.data.data.tir_gender,
            res.data.data.tir_nation,
            res.data.data.tir_id_number,
            res.data.data.tir_home,
            res.data.data.address,
            res.data.data.tel,
            res.data.data.confirm_record,
            res.data.data.inform_right,
            res.data.data.tir_person_answer,
            res.data.data.question_answer_list,
            res.data.data.end_confirm,

    )
  })
}

//问题编辑
const InquiryEditVisible=ref(false);
let question_answer_data_edit=reactive({
  id:0,
  case_id:0,
  question:'',
  answer:'',
})
let idx1: number = -1;
const inquiryEdit=(index: number, row: any)=>{

  row.case_id=create_case.case_id;
  question_answer_data_edit.id=row.id;
  question_answer_data_edit.case_id=row.case_id;
  question_answer_data_edit.question=row.question;
  question_answer_data_edit.answer=row.answer;
  InquiryEditVisible.value=true;
};
//保存编辑
const saveInquiryEdit=()=>{
  InquiryEditVisible.value=false;//将视图关闭
  Transcript_of_questioning_Visible.value=false;   //还需要将查看视图关闭
  fetchData_question_answer_Edit(
          question_answer_data_edit.id,
          question_answer_data_edit.case_id,
          question_answer_data_edit.question,
          question_answer_data_edit.answer,
  ).then(res=>{
    if(res.data.message==="success"){
      getData();
      ElMessage.success('修改成功');
    }else{
      ElMessageBox.confirm('修改失败', '提示', {
        type: 'warning'
      })
    }});
};
//获取询问人
interface interrogator_data{
  staff_id:number,
  staff_name:string
}
//获取询问者选择框
const interrogator_Data=ref<interrogator_data[]>([]);
const get_interrogator_clause_opinion=(staff_id:number,staff_name:string='')=>{
  fetchData_interrogator_clause(staff_id,staff_name).then(res=>{
    interrogator_Data.value=res.data.data
  })
}
get_interrogator_clause_opinion()

//获取记录人
interface recorder_data{
  staff_id:number,
  staff_name:string
}
//获取记录人选择框
const recorder_Data=ref<recorder_data[]>();
const get_recorder_clause_opinion=(staff_id:number,staff_name:string='')=>{
  fetchData_recorder_clause(staff_id,staff_name).then(res=>{
    recorder_Data.value=res.data.data
  })
}
get_recorder_clause_opinion()


//查看询问笔录及确认
const inquiry_record_tabel = (row:any) =>{

  create_case.case_id=row.case_id;
  get_inquiry_record_data_storage(row);
  get_question_answer_Data(row.case_id);
  Transcript_of_questioning_Visible.value = true;
}

const certain_inquiry_record=()=>{

    if (inquiry_record_data_storage.date_of_filing.length==0){
      alert("请输入询问时间")
    }else if(inquiry_record_data_storage.tce_address.length==0){
      alert("请输入询问地点")
    }else if(inquiry_record_data_storage.mer_person.length==0){
      alert("请输入被询问人姓名")
    }else if(inquiry_record_data_storage.gender.length==0){
      alert("请选择性别")
    }else if(inquiry_record_data_storage.tir_age.length==0){
      alert("请输入年龄")
    }else if(inquiry_record_data_storage.nation.length==0){
      alert("请输入民族")
    }else if(inquiry_record_data_storage.native_place.length==0){
      alert("请输入籍贯")
    }else if(inquiry_record_data_storage.identity_card.length==0){
      alert("请输入身份证号码")
    }else if(inquiry_record_data_storage.family_address.length==0){
      alert("请输入家庭住址")
    }else if(inquiry_record_data_storage.business_address.length==0){
      alert("请输入经营地址")
    }else if(inquiry_record_data_storage.telephone_number.length==0){
      alert("请输入联系电话")
    }else if (inquiry_record_data_storage.user_name_1.length==0){
      alert("请输入询问人")
    }else if (inquiry_record_data_storage.user_name_2.length==0){
      alert("请输入询问人")
    }else if(inquiry_record_data_storage.recorder.length==0){
      alert("请输入记录人")
    }else{
      create_case.tcs_note = "询问笔录已完成"
      //将当事人信息传入后修改
      fetchData_inquiry_record_Confirm(
              create_case.case_id,
              inquiry_record_data_storage.date_of_filing,
              inquiry_record_data_storage.tce_address,
              inquiry_record_data_storage.user_id_1,
              inquiry_record_data_storage.user_name_1,
              inquiry_record_data_storage.user_id_2,
              inquiry_record_data_storage.user_name_2,
              inquiry_record_data_storage.recorder,
              inquiry_record_data_storage.mer_person,
              inquiry_record_data_storage.gender,
              inquiry_record_data_storage.nation,
              inquiry_record_data_storage.identity_card,
              inquiry_record_data_storage.family_address,
              inquiry_record_data_storage.business_address,
              inquiry_record_data_storage.telephone_number,
              inquiry_record_data_storage.tir_age,
              inquiry_record_data_storage.native_place,
      ).then(res=>{
        if (res.data.message === "success"){
          getData()
          fetchData_case_update(create_case.case_id,create_case.tcs_note).then(res=>{
            if (res.data.message === "success"){
              ElMessage.success('询问笔录已完成');
              getData();
              Transcript_of_questioning_Visible.value = false;
            }else {
              ElMessageBox.confirm('状态更新失败', '提示', {
                type: 'warning'
              })
            }
          })
        }else{
          ElMessageBox.confirm('确认失败', '提示', {
            type: 'warning'
          })
        }});

    }


}



interface Evidence_ciga_data {
  case_id:number,
  evi_number:number,
  ciga_variety:string,
  barcode:string,
  ciga_model:string,
  ciga_price:number,
  inkjet:string,
  evi_id_number:string,

}
const evidence_ciga_Data= ref<Evidence_ciga_data[]>([]);
// 暂存先行保存批准书数据
const case_evi_data = reactive({
  date_of_filing:'',
  year:'',
  month:'',
  day:'',
  evi_id_number:'',
  evi_id_number1:'',
  illegal_behavior:'',
  tlc_id:'',
  mer_person:'',
  mer_id:'',
  tce_type_number:'',
  tce_number:'',
  tce_address:'',
  user_id_1:'',
  user_id_2:'',
  user_name_1:'',
  user_name_2:'',
})

//获取问题
interface question_data{
  id:number,
  question:string
}
const question_Data = ref<question_data[]>([]);
const get_question_clause_opinion=(id:number,question:string='')=>{
  fetchData_question_clause(id,question).then(res=>{
    question_Data.value=res.data.data
  })
}
get_question_clause_opinion()



//问答显示
interface Question_answer_data{
  id:number,
  case_id:number,
  question:string,
  answer:string
}
const question_answer_Data= ref<Question_answer_data[]>([]);
const get_question_answer_Data=(case_id:number)=>{
  question_answer_show(case_id).then(res=>{
    question_answer_Data.value = res.data.data;
  })
}
const question_answer_add=()=>{
  if(question_answer_storage.question.length==0){
    alert("问题不能为空，请重新输入！")
  }else if(question_answer_storage.answer.length==0){
    alert("回答不能为空。请重新输入！")
  }else{
    question_answer_Create(
            create_case.case_id,
            question_answer_storage.question,
            question_answer_storage.answer,
    ).then(res=>{
      question_answer_Data.value=res.data.data;
      if (res.data.message ==="success"){
        ElMessage.success(`添加成功`);
      }
    });
  }

}

const save_inquired_person=()=>{
  if (inquiry_record_data_storage.date_of_filing.length==0){
    alert("请输入询问时间")
  }else if(inquiry_record_data_storage.tce_address.length==0){
    alert("请输入询问地点")
  }else if(inquiry_record_data_storage.mer_person.length==0){
    alert("请输入被询问人姓名")
  }else if(inquiry_record_data_storage.gender.length==0){
    alert("请选择性别")
  }else if(inquiry_record_data_storage.tir_age.length==0){
    alert("请输入年龄")
  }else if(inquiry_record_data_storage.nation.length==0){
    alert("请输入民族")
  }else if(inquiry_record_data_storage.native_place.length==0){
    alert("请输入籍贯")
  }else if(inquiry_record_data_storage.identity_card.length==0){
    alert("请输入身份证号码")
  }else if(inquiry_record_data_storage.family_address.length==0){
    alert("请输入家庭住址")
  }else if(inquiry_record_data_storage.business_address.length==0){
    alert("请输入经营地址")
  }else if(inquiry_record_data_storage.telephone_number.length==0){
    alert("请输入联系电话")
  }else if (inquiry_record_data_storage.user_name_1.length==0){
    alert("请输入询问人")
  }else if (inquiry_record_data_storage.user_name_2.length==0){
    alert("请输入询问人")
  }else if(inquiry_record_data_storage.recorder.length==0){
    alert("请输入记录人")
  }else {
    fetchData_inquiry_record_Confirm(
            create_case.case_id,
            inquiry_record_data_storage.date_of_filing,
            inquiry_record_data_storage.tce_address,
            inquiry_record_data_storage.user_id_1,
            inquiry_record_data_storage.user_name_1,
            inquiry_record_data_storage.user_id_2,
            inquiry_record_data_storage.user_name_2,
            inquiry_record_data_storage.recorder,
            inquiry_record_data_storage.mer_person,
            inquiry_record_data_storage.gender,
            inquiry_record_data_storage.nation,
            inquiry_record_data_storage.identity_card,
            inquiry_record_data_storage.family_address,
            inquiry_record_data_storage.business_address,
            inquiry_record_data_storage.telephone_number,
            inquiry_record_data_storage.tir_age,
            inquiry_record_data_storage.native_place,
    ).then(res=>{
      if (res.data.message === "success"){
        getData()
        ElMessage.success('被询问人信息保存成功');
      }else{
        ElMessageBox.confirm('保存失败', '提示', {
          type: 'warning'
        })
      }});
  }
}

const question_answer_storage=reactive({
  question_selection:'',
  question:'',
  answer:'',
  list:'',
})

const default_answer_show=()=>{

  default_answer(create_case.case_id,question_answer_storage.question_selection).then(res=>{
            question_answer_storage.question=res.data.data.question,
            question_answer_storage.answer=res.data.data.answer
            //question_answer_storage.list=res.data.data.list
          }

  )

}

//问答删除
const question_answer_delete=(index:number,row:any)=>{
  // 二次确认删除
  ElMessageBox.confirm('确定要删除吗？', '提示', {
    type: 'warning'
  }).then(()=>{
    question_answer_clause_delete(row.id).then(res=>{
      if (res.data.message === "success"){
        question_answer_Data.value.splice(index, 1);
        ElMessage.success('删除成功');
      }else{
        ElMessageBox.confirm('删除失败', '提示', {
          type: 'warning'
        })
      }
    })
  })
          .catch(() => {});
}

const move_question_answer=(index:number,row:any)=>{

  question_answer_move(row.id,create_case.case_id).then(res=>{
    if (res.data.message === "success"){
      ElMessage.success('上移成功');
    }else{
      ElMessageBox.confirm('第一个元素无法移动', '提示', {
        type: 'warning'
      })
    }
  })
}


const inquiry_record_browse = (row:any) =>{
  create_case.case_id=row.case_id;
  get_inquiry_record_browse_data();
  Inquiry_record_list_Browse_Visible.value = true;
}






const query = reactive({
  case_id:0,
  case_source:'',
  case_type:'',
  tcs_note_id:'',
  case_number:'',
  pageIndex: 1,
  pageSize: 10
});
const tableData = ref<TableItem[]>([]);
  const tableList = ref<TableItem[]>([]); // 用于存放分页数据的列表
const pageTotal = ref(0);
const name = localStorage.getItem('ms_username');
// 获取表格数据
const getData = (archive_person:string='',case_id:number,case_source:string='',case_type:string='',case_number:string='',tcs_note_id:string='',name:string='') => {
  fetchData_case(archive_person,case_id,case_source,case_type,case_number,tcs_note_id,name).then(res => {
    tableData.value = res.data.data.filter((i: { tcs_note_id: string; }) =>(
            i.tcs_note_id =="涉案烟草价品核案表完成" ||
            i.tcs_note_id =="询问笔录已完成" ||
            i.tcs_note_id =="无证经营公示已完成" ||
            i.tcs_note_id=="调查终结文书已完成"||
            i.tcs_note_id=="案件处理审批已开始"||
            i.tcs_note_id=="集体讨论已开始"||
            i.tcs_note_id=="集体讨论已完成"||
            i.tcs_note_id=="听证已开始"||
            i.tcs_note_id=="听证告知书已完成"||
            i.tcs_note_id=="听证已完成"||
            i.tcs_note_id=="案件处理审批已完成"||
            i.tcs_note_id=="行政处罚事先告知书确认完成"||
            i.tcs_note_id=="行政处罚事先告知书已完成"||
            i.tcs_note_id=="行政处罚决定书确认完成"||
            i.tcs_note_id=="行政处罚决定书已完成"||
            i.tcs_note_id=="行政罚款收据上传完成"||
            i.tcs_note_id=="行政罚款收据已完成"||
            i.tcs_note_id=="结案报告表已完成"||
            i.tcs_note_id=="已完成"||
            i.tcs_note_id=="撤案集体讨论准备"||
            i.tcs_note_id=="撤案集体讨论已开始"

    )  )
    tableList.value = [];
    pageTotal.value = tableData.value.length || 50;
    // 根据页码确定下标位置
    const index: number = query.pageIndex * query.pageSize - query.pageSize;
    for (let i = index; i < index + query.pageSize; i++) {
      // 防止数组下标越界
      if (i <= tableData.value.length - 1) {
        tableList.value.push(tableData.value[i])
      } else {
        // 越界就不再循环
        break;
      }
    }
  });
};
getData('','','','','','',name);
// 查询操作
const handleSearch = (case_number:string='',tcs_note_id:string='',case_source:string='',case_type:string='') => {
  getData('','',case_source,case_type,case_number,tcs_note_id,name);
};
// 分页导航
const handlePageChange = (val: number) => {
  query.pageIndex = val;
  getData('','','','','','',name);
};
</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}


.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.handle-box button{
  background-color: #00a854;
}
:deep(.avatar){
  width: 100px;
  height: 100px;
}
.blue {
  color: rgba(0, 118, 252, 0.79);
}
.mr10 {
  margin-right: 10px;
}
.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}

.default_answer button{
  background-color: #00a854;
}
/*#inspect_record{*/
/*  position: relative;*/
/*  left: 0px;*/
/*  top: -20px;*/

/*}*/
/*.dialog-footer button{*/
/*  background-color: #00a854;*/
/*  color:white;*/
/*}*/
.save_inquired_person button{
  background-color: #00a854;
}
/*#filing_report_review{*/
/*  position: relative;*/
/*  left: 0px;*/
/*  top: -22px;*/
/*}*/
</style>